/**************************************************************************************************
 * light library                                                                                  *
 * Copyright © 2012 David Kretzmer                                                                *
 *                                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software  *
 * and associated documentation files (the "Software"), to deal in the Software without           *
 * restriction,including without limitation the rights to use, copy, modify, merge, publish,      *
 * distribute,sublicense, and/or sell copies of the Software, and to permit persons to whom the   *
 * Software is furnished to do so, subject to the following conditions:                           *
 *                                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies or       *
 * substantial portions of the Software.                                                          *
 *                                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING  *
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND     *
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.        *
 *                                                                                                *
 *************************************************************************************************/

#pragma once

#include "light/light.hpp"

#include <stdexcept>


//=================================================================================================
// Expands either to 'VAR' or throws an exception if 'VAR' is nullptr
//=================================================================================================
#define LIGHT_ASSIGN_DUBIOUS_PTR(VAR) (VAR != nullptr) ? (VAR) : throw ::std::runtime_error("unexpected nullptr: " #VAR)

namespace light
{
namespace diagnostics
{
	//=============================================================================================
	// Exception types of the STL
	// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
	// (descriptions copied from the standard)
	// → std::exception: base class for all exception
	//   • std::logic_error: an error that could presumably be detected before program execution
	//     ◦ std::domain_error: a variable has none of the expected values
	//     ◦ std::invalid_argument: function argument is invalid
	//     ◦ std::length_error: attempt to create/resize an object whose size (length) exceeds the
	//       maximum size
	//     ◦ std::out_of_range: the variable is not in the allowed range
	//   • std::runtime_error: an error that is only detectable when the program is executed
	//     ◦ std::range_error: for example, max is smaller than min
	//     ◦ std::overflow_error: arithmetic overflow
	//     ◦ std::underflow_error: arithmetic underflow
	//
	// See http://www.drdobbs.com/184401836 on how and when to use exceptions (by Herb Sutter)
	//
	//=============================================================================================

	using ::std::exception;
	using ::std::runtime_error;
	using ::std::overflow_error;
	using ::std::underflow_error;


} // namespace: diagnostics

using diagnostics::exception;
using diagnostics::runtime_error;
using diagnostics::overflow_error;
using diagnostics::underflow_error;

} // namespace: light
